/**
 * @Author：ming
 * @Date：2023/9/27 5:39 PM
 * @Filename：lc151
 */

/**
 * @author ming
 */
public class lc151 {
    public String reverseWords(String s) {
        s = s.trim();
        String[] split = s.split(" \\s+");
        for (int i = 0; i < split.length/2; i++) {
            String temp = split[i];
            split[i] = split[split.length-1-i];
            split[split.length-1-i] = temp;
        }

        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < split.length; i++) {
            sb.append(split[i]);
            if(i<split.length-1){
                sb.append(" ");
            }
        }

        return sb.toString();
    }
}
